package demo519Map;

import demo519.Emp;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class DemoMap {
    public static void main(String[] args) {
        TestMap testMap = new TestMap();
        Map<String, Emp> empMap = new HashMap<>();

        boolean flag = true;
        while (flag) {
            System.out.println("欢迎来到员工系统");
            System.out.println("0.退出系统");
            System.out.println("1.添加员工");
            System.out.println("2.查询所有员工");
            System.out.println("3.根据姓名查询员工");
            System.out.println("4.根据编号删除员工");
            System.out.println("5.根据编号查询员工");
            System.out.println("6.根据编号改年龄");
            System.out.println("请选择功能");
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();

            switch (n) {
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;

                case 1:
                    System.out.println("欢迎来到添加界面");
                    System.out.println("请输入员工的编号");
                    String addNumber = scanner.next();
                    System.out.println("请输入员工姓名");
                    String addName = scanner.next();
                    System.out.println("请输入员工的年龄");
                    int addAge = scanner.nextInt();

                    Emp emp = new Emp();
                    emp.setNumber(addNumber);
                    emp.setName(addName);
                    emp.setAge(addAge);

                    testMap.addEmp(empMap, emp);
                    System.out.println("员工添加成功：" + emp);
                    break;

                case 2:
                    System.out.println("查询所有员工");
                    testMap.findAllEmp(empMap);
                    break;

                case 3:
                    System.out.println("根据姓名查询员工");
                    System.out.println("查询员工姓名");
                    String empName = scanner.next();
                    testMap.findEmpByName(empMap, empName);
                    break;

                case 4:
                    System.out.println("删除员工信息");
                    System.out.println("请输入要删除的员工编号");
                    String empNumber = scanner.next();
                    testMap.deleteEmp(empMap, empNumber);
                    break;

                case 5:
                    System.out.println("根据编号查询员工");
                    System.out.println("查询员工编号");
                    empNumber = scanner.next();
                    Emp foundEmp = testMap.findEmpByNumber(empMap, empNumber);
                    System.out.println(foundEmp != null ? foundEmp : "未找到该员工");
                    break;

                case 6:
                    System.out.println("根据编号改年龄");
                    System.out.println("请输入需查询员工编号");
                    String updateNumber = scanner.next();
                    System.out.println("请输入需改的年龄");
                    int updateAge = scanner.nextInt();

                    Emp empToUpdate = testMap.findEmpByNumber(empMap, updateNumber);
                    if (empToUpdate != null) {
                        empToUpdate.setAge(updateAge);
                        System.out.println("更新成功，当前员工信息：" + empToUpdate);
                    } else {
                        System.out.println("未找到该员工，更新失败");
                    }
                    break;
            }
        }
    }
}
